﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Core.DS;

namespace Web.Controllers
{
    public partial class datastructController : JsonController
    {
        [NeedLogon]
        public ActionResult uploadReport(int eid, HttpPostedFileBase userfile)
        {
            IsFileUpload = true;
            CheckNull(userfile);
            var filename = userfile.FileName;
            var ext = System.IO.Path.GetExtension(filename).ToLower();
            bool ok = false;
            foreach (var e in new[] { ".doc"})
                if (ext == e)
                {
                    ok = true;
                    break;
                }
            if (!ok) return Json(new
            {
                success = false,
                msg = "不支持上传的实验报告！"
            });
            return Json(statistics.uploadReport(eid, Certify.username, userfile, ext));
        }

        [NeedLogon]
        public ActionResult isReportUploaded(int eid)
        {
            return Json(statistics.isReportUploaded(eid, Certify.username));
        }

        [OnlyTeacherUp]
        public ActionResult getDSStatistics(int eid, int cid)
        {
            return Json(statistics.getDSStatistics(eid, cid));
        }

        [OnlyTeacherUp]
        public ActionResult getDSCharPidSet(int eid)
        {
            return Json(statistics.getDSCharPidSet(eid));
        }

        [OnlyTeacherUp]
        public ActionResult submitPoint(string sid, int point)
        {
            return Json(statistics.submitPoint(sid, point));
        }
    }
}
